﻿using System;
using System.Collections;
using StockTrader.DAL.HoseAdapter.FileParser.Structure;
using StockTrader.DAL.HoseAdapter.FileParser;
using StockTrader.DAL.HoseAdapter.BusinessLogic;
using System.Configuration;
using System.Collections.Generic;

namespace StockTrader.DAL.HoseAdapter.DataAccess
{
    public class DataAccessClient
    {
        private static DateTime transDate = TransSchedule.getTransDate();
        private static ArrayList securities = FileEngineer.RetrieveFileInfo(transDate, typeof(Securities));
        private static SortedList<int, CompactLe> ll = new SortedList<int, CompactLe>();
        private static SortedList<int, FroomInfo> room = new SortedList<int, FroomInfo>();

        #region CTCI

        public static int UpdateOrderCancellation()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(OrderCancellation));
            int listCount = list.Count;
            int c1Count = dalClient.CountOrderCancellation();

            if ((c1Count > listCount) || (listCount == 0) || (c1Count == 0))
            {
                if (c1Count > 0)
                    dalClient.DeleteOrderCancelation();
                foreach (OrderCancellation item in list)
                    dalClient.InsertOrderCancellation(item.TimeStamp, item.MessageType, item.Firm, item.OrderNumber, item.OrderEntryDate, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (OrderCancellation item in list.GetRange(c1Count, listCount - c1Count))
                    dalClient.InsertOrderCancellation(item.TimeStamp, item.MessageType, item.Firm, item.OrderNumber, item.OrderEntryDate, item.Offset);
            }
            return listCount;
        }

        public static int UpdateOrderConfirmation()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(OrderConfirmation));
            int listCount = list.Count;
            int b2Count = dalClient.CountOrderConfirmation();

            if ((b2Count > listCount) || (listCount == 0) || (b2Count == 0))
            {
                if (b2Count > 0)
                    dalClient.DeleteOrderConfirmation();
                foreach (OrderConfirmation item in list)
                    dalClient.InsertOrderConfirmation(item.TimeStamp, item.MessageType, item.Firm, item.OrderNumber, item.OrderEntryDate, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (OrderConfirmation item in list.GetRange(b2Count, listCount - b2Count))
                    dalClient.InsertOrderConfirmation(item.TimeStamp, item.MessageType, item.Firm, item.OrderNumber, item.OrderEntryDate, item.Offset);
            }
            return listCount;
        }

        public static int UpdateOrderChange()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(OrderChange));
            int listCount = list.Count;
            int dbCount = dalClient.CountOrderChange();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount > 0)
                    dalClient.DeleteOrderChange();
                foreach (OrderChange item in list)
                    dalClient.InsertOrderChange(item.TimeStamp, item.MessageType, item.Firm, item.OrderNumber, item.OrderEntrydate, item.ClientID, item.Filter, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (OrderChange item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertOrderChange(item.TimeStamp, item.MessageType, item.Firm, item.OrderNumber, item.OrderEntrydate, item.ClientID, item.Filter, item.Offset);
            }
            return listCount;
        }

        public static int UpdateAdvertisment()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(Advertisment));
            int listCount = list.Count;
            int dbCount = dalClient.CountAdvertisement();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount > 0)
                    dalClient.DeleteAdvertisement();
                foreach (Advertisment item in list)
                    dalClient.InsertAdvertisement(item.TimeStamp, item.MessageType, item.Firm, item.TradeID, item.SecuritySymbol, item.Side, Convert.ToInt64(item.Volume), item.Price, item.Board, item.AddCancelFlag, item.Contact, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (Advertisment item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertAdvertisement(item.TimeStamp, item.MessageType, item.Firm, item.TradeID, item.SecuritySymbol, item.Side, Convert.ToInt64(item.Volume), item.Price, item.Board, item.AddCancelFlag, item.Contact, item.Offset);
            }
            return listCount;
        }

        public static int UpdateOFPTDeal()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(OFPTDeal));
            int listCount = list.Count;
            int dbCount = dalClient.CountOFPTDeal();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount > 0)
                    dalClient.DeleteOFPTDeal();
                foreach (OFPTDeal item in list)
                    dalClient.InsertOFPTDeal(item.Timestamp, item.MessageType, item.Firm, item.TradeID, item.ClientIDBuyer, item.ClientIDSeller, item.SecuritySymbol, item.Price, item.Board, item.DealID, item.Filter1,
                        Convert.ToInt64((item.BrokerPortfolioVolBuyer.Trim().Length > 0) ? item.BrokerPortfolioVolBuyer : "0"),
                        Convert.ToInt64((item.BrokerClientVolBuyer.Trim().Length > 0) ? item.BrokerClientVolBuyer : "0"),
                        Convert.ToInt64((item.MutualFundVolBuyer.Trim().Length > 0) ? item.MutualFundVolBuyer : "0"),
                        Convert.ToInt64((item.BrokerForeignVolBuyer.Trim().Length > 0) ? item.BrokerForeignVolBuyer : "0"),
                        item.Filter2,
                        Convert.ToInt64((item.BrokerPortfolioVolSeller.Trim().Length > 0) ? item.BrokerPortfolioVolSeller : "0"),
                        Convert.ToInt64((item.BrokerClientVolSeller.Trim().Length > 0) ? item.BrokerClientVolSeller : "0"),
                        Convert.ToInt64((item.MutualFundVolSeller.Trim().Length > 0) ? item.MutualFundVolSeller : "0"),
                        Convert.ToInt64((item.BrokerForeignVolSeller.Trim().Length > 0) ? item.BrokerForeignVolSeller : "0"),
                        item.Filter3, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (OFPTDeal item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertOFPTDeal(item.Timestamp, item.MessageType, item.Firm, item.TradeID, item.ClientIDBuyer, item.ClientIDSeller, item.SecuritySymbol, item.Price, item.Board, item.DealID, item.Filter1,
                        Convert.ToInt64((item.BrokerPortfolioVolBuyer.Trim().Length > 0) ? item.BrokerPortfolioVolBuyer : "0"),
                        Convert.ToInt64((item.BrokerClientVolBuyer.Trim().Length > 0) ? item.BrokerClientVolBuyer : "0"),
                        Convert.ToInt64((item.MutualFundVolBuyer.Trim().Length > 0) ? item.MutualFundVolBuyer : "0"),
                        Convert.ToInt64((item.BrokerForeignVolBuyer.Trim().Length > 0) ? item.BrokerForeignVolBuyer : "0"),
                        item.Filter2,
                        Convert.ToInt64((item.BrokerPortfolioVolSeller.Trim().Length > 0) ? item.BrokerPortfolioVolSeller : "0"),
                        Convert.ToInt64((item.BrokerClientVolSeller.Trim().Length > 0) ? item.BrokerClientVolSeller : "0"),
                        Convert.ToInt64((item.MutualFundVolSeller.Trim().Length > 0) ? item.MutualFundVolSeller : "0"),
                        Convert.ToInt64((item.BrokerForeignVolSeller.Trim().Length > 0) ? item.BrokerForeignVolSeller : "0"),
                        item.Filter3, item.Offset);
            }
            return listCount;
        }

        public static int UpdateTFPTDeal()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(TFPTDeal));
            int listCount = list.Count;
            int dbCount = dalClient.CountTFPTDeal();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount > 0)
                    dalClient.DeleteTFPTDeal();
                foreach (TFPTDeal item in list)
                    dalClient.InsertTFPTDeal(item.TimeStamp, item.MessageType, item.FirmSeller, item.TradeIDSeller, item.ClientIDSeller, item.ContraFirmBuyer, item.TradeIDBuyer, item.SecuritySymbol, item.Price, item.Board, item.DealID, item.Filter1, string.IsNullOrEmpty(item.BrokerPortfolioVolSeller.Trim()) ? 0 : Convert.ToInt64(item.BrokerPortfolioVolSeller), string.IsNullOrEmpty(item.BrokerClientVolSeller.Trim()) ? 0 : Convert.ToInt64(item.BrokerClientVolSeller), string.IsNullOrEmpty(item.MutualFundVolSeller.Trim()) ? 0 : Convert.ToInt64(item.MutualFundVolSeller), string.IsNullOrEmpty(item.BrokerForeignVolSeller.Trim()) ? 0 : Convert.ToInt64(item.BrokerForeignVolSeller), item.Filter2, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (TFPTDeal item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertTFPTDeal(item.TimeStamp, item.MessageType, item.FirmSeller, item.TradeIDSeller, item.ClientIDSeller, item.ContraFirmBuyer, item.TradeIDBuyer, item.SecuritySymbol, item.Price, item.Board, item.DealID, item.Filter1, string.IsNullOrEmpty(item.BrokerPortfolioVolSeller.Trim()) ? 0 : Convert.ToInt64(item.BrokerPortfolioVolSeller), string.IsNullOrEmpty(item.BrokerClientVolSeller.Trim()) ? 0 : Convert.ToInt64(item.BrokerClientVolSeller), string.IsNullOrEmpty(item.MutualFundVolSeller.Trim()) ? 0 : Convert.ToInt64(item.MutualFundVolSeller), string.IsNullOrEmpty(item.BrokerForeignVolSeller.Trim()) ? 0 : Convert.ToInt64(item.BrokerForeignVolSeller), item.Filter2, item.Offset);
            }
            return listCount;
        }

        public static int UpdateNewConditionedOrder()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(NewConditionedOrder));
            int listCount = list.Count;
            int i1Count = dalClient.CountNewConditionedOrder();

            if ((i1Count > listCount) || (listCount == 0) || (i1Count == 0))
            {
                if (i1Count > 0)
                    dalClient.DeleteNewConditionedOrder();
                foreach (NewConditionedOrder item in list)
                    dalClient.InsertNewConditionedOrder(item.TimeStamp, item.MessageType, item.Firm, item.TradeID, item.OrderNumber, item.ClientID, item.SecuritySymbol, item.Side, Convert.ToInt64(item.Volume), Convert.ToInt64(item.PublishedVolume), item.Price, item.Board, item.Filter, item.PortClientFlag, item.Filters, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (NewConditionedOrder item in list.GetRange(i1Count, listCount - i1Count))
                    dalClient.InsertNewConditionedOrder(item.TimeStamp, item.MessageType, item.Firm, item.TradeID, item.OrderNumber, item.ClientID, item.SecuritySymbol, item.Side, Convert.ToInt64(item.Volume), Convert.ToInt64(item.PublishedVolume), item.Price, item.Board, item.Filter, item.PortClientFlag, item.Filters, item.Offset);
            }
            return listCount;
        }

        public static int UpdateConfirmOrderCancel()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(ConfirmOrderCancel));
            int listCount = list.Count;
            int c2Count = dalClient.CountConfirmOrderCancel();

            if ((c2Count > listCount) || (listCount == 0) || (c2Count == 0))
            {
                if (c2Count > 0)
                    dalClient.DeleteConfirmOrderCancel();
                foreach (ConfirmOrderCancel item in list)
                    dalClient.InsertConfirmOrderCancel(item.Timestamp, item.MessageType, item.Firm, Convert.ToInt64(item.CancelShares), item.OrderNumber, item.OrderEntryDate, item.OrderCancelStatus, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (ConfirmOrderCancel item in list.GetRange(c2Count, listCount - c2Count))
                    dalClient.InsertConfirmOrderCancel(item.Timestamp, item.MessageType, item.Firm, Convert.ToInt64(item.CancelShares), item.OrderNumber, item.OrderEntryDate, item.OrderCancelStatus, item.Offset);
            }
            return listCount;
        }

        public static int UpdateConfirmOrderChange()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(ConfirmOrderChange));
            int listCount = list.Count;
            int dbCount = dalClient.CountConfirmOrderChange();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount > 0)
                    dalClient.DeleteConfirmOrderChange();
                foreach (ConfirmOrderChange item in list)
                    dalClient.InsertConfirmOrderChange(item.Timestamp, item.MessageType, item.Firm, item.OrderNumber, item.OrderEntryDate, item.ClientID, item.PortClientFlag, Convert.ToInt64(item.PublishedVolume.Trim().Length.Equals(0) ? "0" : item.PublishedVolume), item.Price, item.Filter, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (ConfirmOrderChange item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertConfirmOrderChange(item.Timestamp, item.MessageType, item.Firm, item.OrderNumber, item.OrderEntryDate, item.ClientID, item.PortClientFlag, Convert.ToInt64(item.PublishedVolume.Trim().Length.Equals(0) ? "0" : item.PublishedVolume), item.Price, item.Filter, item.Offset);
            }
            return listCount;
        }

        public static int UpdateDealConfirmation()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(DealConfirmation));
            int listCount = list.Count;
            int e2Count = dalClient.CountDealConfirmation();

            if ((e2Count > listCount) || (listCount == 0) || (e2Count == 0))
            {
                if (e2Count > 0)
                    dalClient.DeleteDealConfirmation();
                foreach (DealConfirmation item in list)
                    dalClient.InsertDealConfirmation(item.Timestamp, item.MessageType, item.Firm, item.Side, item.OrderNumber, item.OrderEntryDate, item.Filter, Convert.ToInt64(item.Volume), item.Price, item.ConfirmNumber, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (DealConfirmation item in list.GetRange(e2Count, listCount - e2Count))
                    dalClient.InsertDealConfirmation(item.Timestamp, item.MessageType, item.Firm, item.Side, item.OrderNumber, item.OrderEntryDate, item.Filter, Convert.ToInt64(item.Volume), item.Price, item.ConfirmNumber, item.Offset);
            }
            return list.Count;
        }

        public static int UpdatePutThroughACK()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(PutThroughACK));
            int listCount = list.Count;
            int dbCount = dalClient.CountPutThroughAcknowledgement();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount > 0)
                    dalClient.DeletePutThroughAcknowledgement();
                foreach (PutThroughACK item in list)
                    dalClient.InsertPutThroughAcknowledgement(item.Timestamp, item.MessageType, item.FirmB, item.TradeIDB, item.Side, item.ContraFirmS, item.TradeIDS, item.SecuritySymbol, Convert.ToInt64(item.Volume), item.Price, item.Board, item.ConfirmNumber, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (PutThroughACK item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertPutThroughAcknowledgement(item.Timestamp, item.MessageType, item.FirmB, item.TradeIDB, item.Side, item.ContraFirmS, item.TradeIDS, item.SecuritySymbol, Convert.ToInt64(item.Volume), item.Price, item.Board, item.ConfirmNumber, item.Offset);
            }
            return listCount;
        }

        public static int UpdateReject()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(Reject));
            int listCount = list.Count;
            int dbCount = dalClient.CountReject();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount > 0)
                    dalClient.DeleteReject();
                foreach (Reject item in list)
                    dalClient.InsertReject(item.Timestamp, item.MessageType, item.Firm, item.RejectReasonCode, item.MessageText, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (Reject item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertReject(item.Timestamp, item.MessageType, item.Firm, item.RejectReasonCode, item.MessageText, item.Offset);
            }
            return listCount;
        }

        public static int UpdateCrossingDealConfirm()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(CrossingDealConfirm));
            int listCount = list.Count;
            int dbCount = dalClient.CountCrossDealConfirm();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount > 0)
                    dalClient.DeleteCrossDealConfirm();
                foreach (CrossingDealConfirm item in list)
                    dalClient.InsertCrossDealConfirm(item.Timestamp, item.MessageType, item.Firm, item.OrderNumberB, item.OrderEntryDateB, item.OrderNumberS, item.OrderEntryDateS, Convert.ToInt64(item.Volume), item.Price, item.ConfirmNumber, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (CrossingDealConfirm item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertCrossDealConfirm(item.Timestamp, item.MessageType, item.Firm, item.OrderNumberB, item.OrderEntryDateB, item.OrderNumberS, item.OrderEntryDateS, Convert.ToInt64(item.Volume), item.Price, item.ConfirmNumber, item.Offset);
            }
            return listCount;
        }

        public static int UpdatePutThroughDealConfirmation()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(PutThroughDealConfirmation));
            int listCount = list.Count;
            int dbCount = dalClient.CountPutThroughDealConfirmation();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount > 0)
                    dalClient.DeletePutThroughDealConfirmation();
                foreach (PutThroughDealConfirmation item in list)
                    dalClient.InsertPutThroughDealConfirmation(item.Timestamp, item.MessageType, item.Firm, item.Side, item.DealID, item.ContraFirm, Convert.ToInt64(item.Volume), item.Price, item.ConfirmNumber, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (PutThroughDealConfirmation item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertPutThroughDealConfirmation(item.Timestamp, item.MessageType, item.Firm, item.Side, item.DealID, item.ContraFirm, Convert.ToInt64(item.Volume), item.Price, item.ConfirmNumber, item.Offset);
            }
            return listCount;
        }

        public static int UpdatePutThroughDealReply()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(PutThroughDealReply));
            int listCount = list.Count;
            int dbCount = dalClient.CountPutThroughDealReply();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount > 0)
                    dalClient.DeletePutThroughDealReply();
                foreach (PutThroughDealReply item in list)
                    dalClient.InsertPutThroughDealReply(item.Timestamp, item.MessageType, item.Firm, item.ConfirmNumber, item.DealID, item.ClientIDB, item.ReplyCode, item.Filter, Convert.ToInt64((item.BrokerPortfolioVolB.Trim().Length > 0) ? item.BrokerPortfolioVolB : "0"), Convert.ToInt64((item.BrokerClientVolB.Trim().Length > 0) ? item.BrokerClientVolB : "0"), Convert.ToInt64((item.MutualFundVolB.Trim().Length > 0) ? item.MutualFundVolB : "0"), Convert.ToInt64((item.BrokerForeignVolB.Trim().Length > 0) ? item.BrokerForeignVolB : "0"), item.FilterS, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (PutThroughDealReply item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertPutThroughDealReply(item.Timestamp, item.MessageType, item.Firm, item.ConfirmNumber, item.DealID, item.ClientIDB, item.ReplyCode, item.Filter, Convert.ToInt64((item.BrokerPortfolioVolB.Trim().Length > 0) ? item.BrokerPortfolioVolB : "0"), Convert.ToInt64((item.BrokerClientVolB.Trim().Length > 0) ? item.BrokerClientVolB : "0"), Convert.ToInt64((item.MutualFundVolB.Trim().Length > 0) ? item.MutualFundVolB : "0"), Convert.ToInt64((item.BrokerForeignVolB.Trim().Length > 0) ? item.BrokerForeignVolB : "0"), item.FilterS, item.Offset);
            }
            return listCount;
        }

        public static int UpdateDealCancelRequest()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(DealCancelRequest));
            int listCount = list.Count;
            int dbCount = dalClient.CountDealPutThroughCancelRequest();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount != 0)
                    dalClient.DeleteDealPutThroughCancelRequest();
                foreach (DealCancelRequest item in list)
                    dalClient.InsertDealPutThroughCancelRequest(item.Timestamp, item.MessageType, item.Firm, item.ContraFirm, item.TradeID, item.ConfirmNumber, item.SecuritySymbol, item.Side, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (DealCancelRequest item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertDealPutThroughCancelRequest(item.Timestamp, item.MessageType, item.Firm, item.ContraFirm, item.TradeID, item.ConfirmNumber, item.SecuritySymbol, item.Side, item.Offset);
            }
            return listCount;
        }

        public static int UpdateDealCancelReply()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(DealCancelReply));
            int listCount = list.Count;
            int dbCount = dalClient.CountDealCancelReply();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount != 0)
                    dalClient.DeleteDealCancelReply();
                foreach (DealCancelReply item in list)
                    dalClient.InsertDealCancelReply(item.Timestamp, item.MessageType, item.Firm, item.ConfirmNumber, item.ReplyCode, item.Offset);
            }
            else
            {
                //Insert only the change part!
                foreach (DealCancelReply item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertDealCancelReply(item.Timestamp, item.MessageType, item.Firm, item.ConfirmNumber, item.ReplyCode, item.Offset);
            }
            return listCount;
        }

        #endregion

        #region PRS

        public static int UpdateSecurity()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(Securities));
            //ArrayList listLe = FileEngineer.RetrieveFileInfo(transDate, typeof(Le));

            int listCount = list.Count;
            int dbCount = dalClient.CountSecurities();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount != 0)
                    dalClient.DeleteSecurities();
                foreach (Securities item in list)
                {
                    if (!item.StockType.Trim().Equals("D"))
                        dalClient.UpdateSecuritiesInfo(item.Stockno, item.StockSymbol, "HOSE");
                    dalClient.InsertSecurities(item.Stockno, item.StockSymbol, item.StockType, item.Ceilling, item.Floor, item.BiglotValue, item.SercurityName, item.Sectorno, item.DesigNated, item.Suspension, item.Delist, item.HaltReSumFlag, item.Split, item.Benefit, item.Meeting, item.Notice, item.ClientIDRequest, item.CouponRate, item.IssueDate, item.MatureDate, item.AvrpPrice, item.ParValue, item.SdcFlag, item.PriorClosePrice, item.PriorCloseDate, item.ProjectOpen, item.OpenPrice, item.Last, item.LastVol, item.LastVal, item.Highest, item.Lowest, item.TotalShare, item.TotalValue, item.AccumuLateDeal, item.BigDeal, item.BigVol, item.BigVal, item.OddVol, item.OddVal, item.Best3Bid, item.Best3BidVolume, item.Best2Bid, item.Best2BidVolume, item.Best1Bid, item.Best1BidVolume, item.Best1Offer, item.Best1OfferVolume, item.Best2Offer, item.Best2OfferVolume, item.Best3Offer, item.Best3OfferVolume, item.BoardLost);
                }
            }
            else if (dbCount < listCount)
            {
                //Insert only the change part!
                foreach (Securities item in list.GetRange(dbCount, listCount - dbCount))
                {
                    if (!item.StockType.Trim().Equals("D"))
                        dalClient.UpdateSecuritiesInfo(item.Stockno, item.StockSymbol, "HOSE");

                    dalClient.InsertSecurities(item.Stockno, item.StockSymbol, item.StockType, item.Ceilling, item.Floor, item.BiglotValue, item.SercurityName, item.Sectorno, item.DesigNated, item.Suspension, item.Delist, item.HaltReSumFlag, item.Split, item.Benefit, item.Meeting, item.Notice, item.ClientIDRequest, item.CouponRate, item.IssueDate, item.MatureDate, item.AvrpPrice, item.ParValue, item.SdcFlag, item.PriorClosePrice, item.PriorCloseDate, item.ProjectOpen, item.OpenPrice, item.Last, item.LastVol, item.LastVal, item.Highest, item.Lowest, item.TotalShare, item.TotalValue, item.AccumuLateDeal, item.BigDeal, item.BigVol, item.BigVal, item.OddVol, item.OddVal, item.Best3Bid, item.Best3BidVolume, item.Best2Bid, item.Best2BidVolume, item.Best1Bid, item.Best1BidVolume, item.Best1Offer, item.Best1OfferVolume, item.Best2Offer, item.Best2OfferVolume, item.Best3Offer, item.Best3OfferVolume, item.BoardLost);
                }
            }
            else if (dbCount == listCount)
            {
                foreach (Securities item in list)
                    if (!item.StockType.Trim().Equals("D"))
                    {
                        dalClient.UpdateSecuritiesInfo(item.Stockno, item.StockSymbol, "HOSE");
                        dalClient.UpdateSecuritiesByStockSymbol(item.DesigNated, item.Suspension, item.Delist, item.HaltReSumFlag, item.Split, item.Benefit, item.Meeting, item.Notice, item.ClientIDRequest, item.CouponRate, item.IssueDate, item.MatureDate, item.AvrpPrice, item.ParValue, item.SdcFlag, item.ProjectOpen, item.Last, item.LastVol, item.LastVal, item.Highest, item.Lowest, item.TotalShare, item.TotalValue, item.AccumuLateDeal, item.BigDeal, item.BigVol, item.BigVal, item.OddVol, item.OddVal, item.Best3Bid, item.Best3BidVolume, item.Best2Bid, item.Best2BidVolume, item.Best1Bid, item.Best1BidVolume, item.Best1Offer, item.Best1OfferVolume, item.Best2Offer, item.Best2OfferVolume, item.Best3Offer, item.Best3OfferVolume, item.BoardLost, item.OpenPrice, item.StockSymbol);
                    }
            }
            return listCount;
        }

        public static int UpdateMarketStat()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(MarketStat));
            int listCount = list.Count;
            int dbCount = dalClient.CountMarketStat();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount != 0)
                    dalClient.DeleteMarketStat();
                foreach (MarketStat item in list)
                    dalClient.InsertMarketStat(item.ControlCode, item.Time);
            }
            else
            {
                //Insert only the change part!
                foreach (MarketStat item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertMarketStat(item.ControlCode, item.Time);
            }
            return listCount;
        }

        public static int UpdateTotalMkt()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(TotalMkt));
            int listCount = list.Count;
            int dbCount = dalClient.CountTotalMkt();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount != 0)
                    dalClient.DeleteTotalMkt();
                foreach (TotalMkt item in list)
                    dalClient.InsertTotalMkt(item.VNIndex, item.TotalTrade, item.TotalShares, item.TotalValues, item.UpVolume, item.NoChangeVolume, item.DownVolume, item.Advances, item.Declines, item.NoChange, item.VN50Index, item.MarketID, item.Filter, item.Time);
            }
            else
            {
                //Insert only the change part!
                foreach (TotalMkt item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertTotalMkt(item.VNIndex, item.TotalTrade, item.TotalShares, item.TotalValues, item.UpVolume, item.NoChangeVolume, item.DownVolume, item.Advances, item.Declines, item.NoChange, item.VN50Index, item.MarketID, item.Filter, item.Time);
            }
            return listCount;
        }

        public static int UpdatePutAd()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(PutAd));
            int listCount = list.Count;
            int dbCount = dalClient.CountPutAd();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount != 0)
                    dalClient.DeletePutAd();
                foreach (PutAd item in list)
                    dalClient.InsertPutAd(item.TradeID, item.StockNo, item.Vol, item.Price, item.FirmNo, item.Side, item.Board, item.Time, item.Flag);
            }
            else
            {
                //Insert only the change part!
                foreach (PutAd item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertPutAd(item.TradeID, item.StockNo, item.Vol, item.Price, item.FirmNo, item.Side, item.Board, item.Time, item.Flag);
            }
            return listCount;
        }

        public static int UpdatePutExec()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(PutExec));
            int listCount = list.Count;
            int dbCount = dalClient.CountPutExec();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount != 0)
                    dalClient.DeletePutExec();
                foreach (PutExec item in list)
                    dalClient.InsertPutExec(item.ConfirmNo, item.StockNo, item.Vol, item.Price, item.Board);
            }
            else
            {
                //Insert only the change part!
                foreach (PutExec item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertPutExec(item.ConfirmNo, item.StockNo, item.Vol, item.Price, item.Board);
            }
            return listCount;
        }

        public static int UpdatePutDc()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(PutDc));
            int listCount = list.Count;
            int dbCount = dalClient.CountPutDc();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount != 0)
                    dalClient.DeletePutDc();
                foreach (PutDc item in list)
                    dalClient.InsertPutDc(item.ConfirmNo, item.StockNo, item.Vol, item.Price, item.Board);
            }
            else
            {
                //Insert only the change part!
                foreach (PutDc item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertPutDc(item.ConfirmNo, item.StockNo, item.Vol, item.Price, item.Board);
            }
            return listCount;
        }

        public static int UpdateLe()
        {
            try
            {
                Adapter dalClient = new Adapter();
                ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(Le));
                CompactLe temp;
                int listCount = list.Count;
                int lecount = dalClient.CountLe();


                if ((lecount > listCount) || (listCount == 0) || (lecount == 0))
                {
                    if (lecount > 0)
                        dalClient.DeleteLe();
                    foreach (Le item in list)
                    {
                        if (ll.TryGetValue(item.StockNo, out temp))
                        {
                            ll[item.StockNo].Price = item.Price;
                            ll[item.StockNo].Volume = ((item.AccumulatedVol - ll[item.StockNo].AccumulatedVol) > 0) ? ((item.AccumulatedVol) - ll[item.StockNo].AccumulatedVol) : ll[item.StockNo].Volume;
                            if (item.Time < 90030)
                            {
                                ll[item.StockNo].VolP1 = (item.AccumulatedVol > ll[item.StockNo].VolP1) ? item.AccumulatedVol : ll[item.StockNo].VolP1;
                                ll[item.StockNo].ValP1 = Convert.ToInt32((item.AccumulatedVal > ll[item.StockNo].ValP1) ? item.AccumulatedVal : ll[item.StockNo].ValP1);
                            }
                            if (item.Time < 102000)
                            {
                                int volp2 = item.AccumulatedVol - ll[item.StockNo].VolP1;
                                double valp2 = item.AccumulatedVal - ll[item.StockNo].ValP1;
                                ll[item.StockNo].VolP2 = (volp2 > ll[item.StockNo].VolP2) ? volp2 : ll[item.StockNo].VolP2;
                                ll[item.StockNo].ValP2 = Convert.ToInt32((valp2 > ll[item.StockNo].ValP2) ? valp2 : ll[item.StockNo].ValP2);
                            }
                            ll[item.StockNo].Time = (item.Time > ll[item.StockNo].Time) ? item.Time : ll[item.StockNo].Time;
                            ll[item.StockNo].AccumulatedVol = (item.AccumulatedVol > ll[item.StockNo].AccumulatedVol) ? item.AccumulatedVol : ll[item.StockNo].AccumulatedVol;
                        }
                        else
                        {
                            ll.Add(item.StockNo, new CompactLe(item.StockNo, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                            ll[item.StockNo].Price = item.Price;
                            ll[item.StockNo].Volume = ((item.AccumulatedVol - ll[item.StockNo].AccumulatedVol) > 0) ? ((item.AccumulatedVol) - ll[item.StockNo].AccumulatedVol) : ll[item.StockNo].Volume;
                            if (item.Time < 90030)
                            {
                                ll[item.StockNo].VolP1 = (item.AccumulatedVol > ll[item.StockNo].VolP1) ? item.AccumulatedVol : ll[item.StockNo].VolP1;
                                ll[item.StockNo].ValP1 = Convert.ToInt32((item.AccumulatedVal > ll[item.StockNo].ValP1) ? item.AccumulatedVal : ll[item.StockNo].ValP1);
                            }
                            if (item.Time < 102000)
                            {
                                int volp2 = item.AccumulatedVol - ll[item.StockNo].VolP1;
                                double valp2 = item.AccumulatedVal - ll[item.StockNo].ValP1;
                                ll[item.StockNo].VolP2 = (volp2 > ll[item.StockNo].VolP2) ? volp2 : ll[item.StockNo].VolP2;
                                ll[item.StockNo].ValP2 = Convert.ToInt32((valp2 > ll[item.StockNo].ValP1) ? valp2 : ll[item.StockNo].ValP2);
                            }
                            ll[item.StockNo].Time = (item.Time > ll[item.StockNo].Time) ? item.Time : ll[item.StockNo].Time;
                            ll[item.StockNo].AccumulatedVol = (item.AccumulatedVol > ll[item.StockNo].AccumulatedVol) ? item.AccumulatedVol : ll[item.StockNo].AccumulatedVol;
                        }
                        dalClient.InsertLe(item.StockNo, item.Price, item.AccumulatedVol, item.AccumulatedVal, item.Highest, item.Lowest, item.Time);
                    }
                }
                else
                {
                    foreach (Le item in list.GetRange(lecount, listCount - lecount))
                    {
                        if (ll.TryGetValue(item.StockNo, out temp))
                        {
                            ll[item.StockNo].Price = item.Price;
                            ll[item.StockNo].Volume = ((item.AccumulatedVol - ll[item.StockNo].AccumulatedVol) > 0) ? ((item.AccumulatedVol) - ll[item.StockNo].AccumulatedVol) : ll[item.StockNo].Volume;
                            if (item.Time < 90030)
                            {
                                ll[item.StockNo].VolP1 = (item.AccumulatedVol > ll[item.StockNo].VolP1) ? item.AccumulatedVol : ll[item.StockNo].VolP1;
                                ll[item.StockNo].ValP1 = Convert.ToInt32((item.AccumulatedVal > ll[item.StockNo].ValP1) ? item.AccumulatedVal : ll[item.StockNo].ValP1);
                            }
                            if (item.Time < 102000)
                            {
                                int volp2 = item.AccumulatedVol - ll[item.StockNo].VolP1;
                                double valp2 = item.AccumulatedVal - ll[item.StockNo].ValP1;
                                ll[item.StockNo].VolP2 = (volp2 > ll[item.StockNo].VolP2) ? volp2 : ll[item.StockNo].VolP2;
                                ll[item.StockNo].ValP2 = Convert.ToInt32((valp2 > ll[item.StockNo].ValP1) ? valp2 : ll[item.StockNo].ValP2);
                            }
                            ll[item.StockNo].Time = (item.Time > ll[item.StockNo].Time) ? item.Time : ll[item.StockNo].Time;
                            ll[item.StockNo].AccumulatedVol = (item.AccumulatedVol > ll[item.StockNo].AccumulatedVol) ? item.AccumulatedVol : ll[item.StockNo].AccumulatedVol;
                        }
                        else
                        {
                            ll.Add(item.StockNo, new CompactLe(item.StockNo, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                            ll[item.StockNo].Price = item.Price;
                            ll[item.StockNo].Volume = ((item.AccumulatedVol - ll[item.StockNo].AccumulatedVol) > 0) ? ((item.AccumulatedVol) - ll[item.StockNo].AccumulatedVol) : ll[item.StockNo].Volume;
                            if (item.Time < 90030)
                            {
                                ll[item.StockNo].VolP1 = (item.AccumulatedVol > ll[item.StockNo].VolP1) ? item.AccumulatedVol : ll[item.StockNo].VolP1;
                                ll[item.StockNo].ValP1 = Convert.ToInt32((item.AccumulatedVal > ll[item.StockNo].ValP1) ? item.AccumulatedVal : ll[item.StockNo].ValP1);
                            }
                            if (item.Time < 102000)
                            {
                                int volp2 = item.AccumulatedVol - ll[item.StockNo].VolP1;
                                double valp2 = item.AccumulatedVal - ll[item.StockNo].ValP1;
                                ll[item.StockNo].VolP2 = (volp2 > ll[item.StockNo].VolP2) ? volp2 : ll[item.StockNo].VolP2;
                                ll[item.StockNo].ValP2 = Convert.ToInt32((valp2 > ll[item.StockNo].ValP1) ? valp2 : ll[item.StockNo].ValP2);
                            }
                            ll[item.StockNo].Time = (item.Time > ll[item.StockNo].Time) ? item.Time : ll[item.StockNo].Time;
                            ll[item.StockNo].AccumulatedVol = (item.AccumulatedVol > ll[item.StockNo].AccumulatedVol) ? item.AccumulatedVol : ll[item.StockNo].AccumulatedVol;
                        }

                        dalClient.InsertLe(item.StockNo, item.Price, item.AccumulatedVol, item.AccumulatedVal, item.Highest, item.Lowest, item.Time);
                    }
                }
                if (ll.Count > 0)
                    foreach (KeyValuePair<int, CompactLe> item in ll)
                    {
                        dalClient.InsertLeCompact(item.Value.StockNo, item.Value.Price, item.Value.Volume, item.Value.VolP1, item.Value.ValP1, item.Value.VolP2, item.Value.ValP2, item.Value.Time);
                    }

                return lecount;
            }
            catch (System.Exception e)
            {
                return 0;
            }
        }


        public static int UpdateNewList()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(NewList));
            int listCount = list.Count;
            int dbCount = dalClient.CountNewList();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount != 0)
                    dalClient.DeleteNewList();
                foreach (NewList item in list)
                    dalClient.InsertNewList(item.StockNo, item.StockSymbol, item.StockType, item.StockName, item.SectorNo);
            }
            else
            {
                //Insert only the change part!
                foreach (NewList item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertNewList(item.StockNo, item.StockSymbol, item.StockType, item.StockName, item.SectorNo);
            }
            return listCount;
        }

        public static int UpdateDeList()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(DeList));
            int listCount = list.Count;
            int dbCount = dalClient.CountDeList();

            if ((dbCount > listCount) || (listCount == 0) || (dbCount == 0))
            {
                if (dbCount != 0)
                    dalClient.DeleteDeList();
                foreach (DeList item in list)
                    dalClient.InsertDeList(item.StockNo, item.StockSymbol, item.StockType, item.StockName, item.SectorNo);
            }
            else
            {
                //Insert only the change part!
                foreach (DeList item in list.GetRange(dbCount, listCount - dbCount))
                    dalClient.InsertDeList(item.StockNo, item.StockSymbol, item.StockType, item.StockName, item.SectorNo);
            }
            return listCount;
        }

        public static int UpdateFroom()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(Froom));
            FroomInfo temp;
            int listCount = list.Count;
            int roomcount = dalClient.CountFroomOrigin();

            if ((roomcount > listCount) || (listCount == 0) || (roomcount == 0))
            {
                dalClient.DeleteFroomOrigin();
                dalClient.DeleteFroom();
                foreach (Froom nr in list)
                {
                    if (room.TryGetValue(nr.StockNo, out temp))
                    {
                        double lst = room[nr.StockNo].CurrentRoom;
                        if (nr.CurrentRoom > lst)
                            room[nr.StockNo].Sell += Convert.ToInt32(nr.CurrentRoom - lst);
                        if (nr.CurrentRoom < lst)
                            room[nr.StockNo].Buy += Convert.ToInt32(lst - nr.CurrentRoom);
                        room[nr.StockNo].CurrentRoom = nr.CurrentRoom;
                        room[nr.StockNo].TotalRoom = nr.TotalRoom;
                    }
                    else
                    {
                        room.Add(nr.StockNo, new FroomInfo(nr.StockNo, 0, 0, 0, 0));
                        double lst = room[nr.StockNo].CurrentRoom;
                        if (nr.CurrentRoom > lst)
                            room[nr.StockNo].Sell += Convert.ToInt32(nr.CurrentRoom - lst);
                        if (nr.CurrentRoom < lst)
                            room[nr.StockNo].Buy += Convert.ToInt32(lst - nr.CurrentRoom);
                        room[nr.StockNo].CurrentRoom = nr.CurrentRoom;
                        room[nr.StockNo].TotalRoom = nr.TotalRoom;
                    }
                    dalClient.InsertFroomOrigin(nr.StockNo, nr.TotalRoom, nr.CurrentRoom);
                    //dalClient.UpdateFroom(room[nr.StockNo].StockNo, room[nr.StockNo].TotalRoom, room[nr.StockNo].CurrentRoom, room[nr.StockNo].Buy, room[nr.StockNo].Sell);
                }
            }
            else
            {
                foreach (Froom nr in list.GetRange(roomcount, listCount - roomcount))
                {
                    if (room.TryGetValue(nr.StockNo, out temp))
                    {
                        double lst = room[nr.StockNo].CurrentRoom;
                        if (nr.CurrentRoom > lst)
                            room[nr.StockNo].Sell += Convert.ToInt32(nr.CurrentRoom - lst);
                        if (nr.CurrentRoom < lst)
                            room[nr.StockNo].Buy += Convert.ToInt32(lst - nr.CurrentRoom);
                        room[nr.StockNo].CurrentRoom = nr.CurrentRoom;
                        room[nr.StockNo].TotalRoom = nr.TotalRoom;
                    }
                    else
                    {
                        room.Add(nr.StockNo, new FroomInfo(nr.StockNo, 0, 0, 0, 0));
                        double lst = room[nr.StockNo].CurrentRoom;
                        if (nr.CurrentRoom > lst)
                            room[nr.StockNo].Sell += Convert.ToInt32(nr.CurrentRoom - lst);
                        if (nr.CurrentRoom < lst)
                            room[nr.StockNo].Buy += Convert.ToInt32(lst - nr.CurrentRoom);
                        room[nr.StockNo].CurrentRoom = nr.CurrentRoom;
                        room[nr.StockNo].TotalRoom = nr.TotalRoom;
                    }
                    dalClient.InsertFroomOrigin(nr.StockNo, nr.TotalRoom, nr.CurrentRoom);
                    //dalClient.UpdateFroom(room[nr.StockNo].StockNo, room[nr.StockNo].TotalRoom, room[nr.StockNo].CurrentRoom, room[nr.StockNo].Buy, room[nr.StockNo].Sell);
                }
            }
            if (room.Count > 0)
                foreach (KeyValuePair<int, FroomInfo> item in room)
                {
                    dalClient.UpdateFroom(item.Value.StockNo, item.Value.TotalRoom, item.Value.CurrentRoom, item.Value.Buy, item.Value.Sell);
                }
            return roomcount;
        }

        public static int UpdateSecuritiesEarly()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(Securities));
            foreach (Securities item in list)
            {
                if (!item.StockType.Trim().Equals("D"))
                    dalClient.UpdateSecuritiesInfo(item.Stockno, item.StockSymbol, "HOSE");

                dalClient.UpdateSecuritiesEarly(item.Stockno, item.StockSymbol, item.StockType, item.Ceilling, item.Floor, item.BiglotValue, item.SercurityName, item.Sectorno, item.DesigNated, item.Suspension, item.Delist, item.HaltReSumFlag, item.Split, item.Benefit, item.Meeting, item.Notice, item.ClientIDRequest, item.CouponRate, item.IssueDate, item.MatureDate, item.AvrpPrice, item.ParValue, item.SdcFlag, item.PriorClosePrice, item.PriorCloseDate, item.ProjectOpen, item.OpenPrice, item.Last, item.LastVol, item.LastVal, item.Highest, item.Lowest, item.TotalShare, item.TotalValue, item.AccumuLateDeal, item.BigDeal, item.BigVol, item.BigVal, item.OddVol, item.OddVal, item.Best3Bid, item.Best3BidVolume, item.Best2Bid, item.Best2BidVolume, item.Best1Bid, item.Best1BidVolume, item.Best1Offer, item.Best1OfferVolume, item.Best2Offer, item.Best2OfferVolume, item.Best3Offer, item.Best3OfferVolume, item.BoardLost);
            }
            return list.Count;
        }

        public static int UpdateSecuritiesLately()
        {
            Adapter dalClient = new Adapter();
            ArrayList list = FileEngineer.RetrieveFileInfo(transDate, typeof(Securities));
            foreach (Securities item in list)
            {
                if (!item.StockType.Trim().Equals("D"))
                    dalClient.UpdateSecuritiesInfo(item.Stockno, item.StockSymbol, "HOSE");

                dalClient.UpdateSecuritiesLately(item.Stockno, item.StockSymbol, item.StockType, item.Ceilling, item.Floor, item.BiglotValue, item.SercurityName, item.Sectorno, item.DesigNated, item.Suspension, item.Delist, item.HaltReSumFlag, item.Split, item.Benefit, item.Meeting, item.Notice, item.ClientIDRequest, item.CouponRate, item.IssueDate, item.MatureDate, item.AvrpPrice, item.ParValue, item.SdcFlag, item.PriorClosePrice, item.PriorCloseDate, item.ProjectOpen, item.OpenPrice, item.Last, item.LastVol, item.LastVal, item.Highest, item.Lowest, item.TotalShare, item.TotalValue, item.AccumuLateDeal, item.BigDeal, item.BigVol, item.BigVal, item.OddVol, item.OddVal, item.Best3Bid, item.Best3BidVolume, item.Best2Bid, item.Best2BidVolume, item.Best1Bid, item.Best1BidVolume, item.Best1Offer, item.Best1OfferVolume, item.Best2Offer, item.Best2OfferVolume, item.Best3Offer, item.Best3OfferVolume, item.BoardLost);
            }
            return list.Count;
        }

        #endregion

        public void BackupHoseOrders()
        {
            Adapter dalClient = new Adapter();
            try
            {
                dalClient.BackupHoseOrders();
            }
            catch (System.Exception e)
            {
                throw e;
            }
        }
        public void DeleteHoseOrders()
        {
            Adapter dalClient = new Adapter();
            try
            {
                int OrderCount = dalClient.CountNewConditionedOrder();
                if (OrderCount > 0)
                    dalClient.DeleteHoseOrders();
            }
            catch (System.Exception e)
            {
                throw e;
            }
        }

    }
}
